package org.company.mars.activemq;

import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.company.mars.util.MQUtils;

public class QueneProducer {
	
	public void produce() throws JMSException {
		Connection connection = MQUtils.getConnection();
		boolean transacted = false;
		connection.start();
		Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
		
		Destination destination = session.createQueue("TOOL.DEFAULT");
		MessageProducer producer = session.createProducer(destination);
		producer.setDeliveryMode(DeliveryMode.PERSISTENT);
		this.sendAndClose(connection,session, producer);
	}
	
	public void sendAndClose(Connection connection,Session session,MessageProducer producer) throws JMSException  {
	    Message message = session.createTextMessage();
		//session.createObjectMessage();
		//session.createBytesMessage();
		//session.createStreamMessage();
		//session.createTextMessage();
		message.setStringProperty("message", "hello world");
		message.setBooleanProperty("flag", true);
		producer.send(message);
		producer.close();
		session.close();
		connection.close();
	}
}
